export class Verification {
  static checkPhone(value: string): boolean {
    const verPhone = /^1[3456789]\d{9}$/;
    return verPhone.test(value);
  }

  static checkPassword(value: string): boolean {
    const verPassword = /^(?!\D+$)(?![^a-zA-Z]+$)\S{6,20}$/;
    return verPassword.test(value);
  }

  static validator_username (rule: unknown, value: string) {
    const checkPhone = Verification.checkPhone(value);
    if (!value) {
      return new Error('输入用户名');
    } else if (!checkPhone) {
      return new Error('请输入正确的手机号码')
    }
    return true;
  }

  static validator_password (rule: unknown, value: string) {
    const checkPassword = Verification.checkPassword(value);
    if (!value) {
      return new Error('密码不能为空');
    } else if (!checkPassword) {
      return new Error('密码必须为6-20位英文+数字');
    }
    return true;
  }

  static validator_validata (rule: unknown, value: string) {
    if (!value) {
      return new Error('验证码不能为空');
    } else if (value.length !== 6) {
      return new Error('验证码长度必须为6位字符');
    }
    return true;
  }
}